/**
 * 
 */
package com.idea.auction.service;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.idea.auction.model.Commodity;
import com.idea.auction.model.Commodityorder;
import com.idea.auction.model.RolePer;
import com.idea.auction.model.User;
import com.jfinal.aop.Before;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.server.BaseService;

/**
 * @author y.z
 */
public class OrderService extends BaseService<Commodityorder> {
	
	/**
	 * 获取分页
	 * @param curPage		  页码
	 * @param orderNo		  订单号
	 * @param payType		  支付类型
	 * @param orderState	  订单状态
	 * @param recoveryType   回收类型
	 * @param recoveryState	  回收状态
	 * @return
	 */
	public Page<Commodityorder> getPage(int curPage, String orderNo,String payType, String orderState ,String recoveryType ,String recoveryState){
		String sql = "from commodity_order o left join user u on o.user_id = u.id left join commodity c on commodity_id = c.id  where 1=1 ";
		if(!StrKit.isBlank(orderNo)){
			sql += " and o.order_no ="+orderNo;
		}
		
		if(!StrKit.isBlank(payType)){
			sql += " and o.pay_type ="+payType;
		}
		
		if(!StrKit.isBlank(orderState)){
			sql += " and o.order_state ="+orderState;
		}
		
		if(!StrKit.isBlank(recoveryType)){
			sql += " and o.recovery_type ="+recoveryType;
		}
		
		if(!StrKit.isBlank(recoveryState)){
			sql += " and o.recovery_state ="+recoveryState;
		}
		return super.getPage(curPage, "select o.*,u.nick_name,c.commodity_name,c.picture", sql+" order by create_date desc ");
	}
	
	/**
	 * 删除订单
	 * @param id
	 * @return
	 */
	public boolean delete(String id){
		return super.delById(id);
	}
	
	/**
	 * 添加订单
	 * @param Commodity
	 * @return
	 */
	public boolean add(Commodityorder order){
		return super.save(order);
	}
	
	/**
	 * 修改订单
	 * @param Commodity
	 * @return
	 */
	public boolean update(Commodityorder order){
		return super.update(order);
	}
	
	/**
	 * 根据id获取详细
	 * @param id
	 * @return
	 */
	public Commodityorder getOrderById(String id){
		Commodityorder order = super.findFirst("select o.*,u.nick_name,c.commodity_name,c.picture from commodity_order o left join user u on o.user_id = u.id left join commodity c on commodity_id = c.id  where 1=1 ");
		return order;
	}
	
}
